import { defineStore } from 'pinia'
import { ref } from 'vue'

// 定义 Store
export const useWorkmainStore = defineStore(
  'workmain',
  () => {
    // records数据
    const records = ref([])

    // 设置records数据
    const setRecords = (value) => {
      records.value = value
    }
    // 清空records 数据
    const clearRecords = () => {
      records.value = []
    }
    const deleteRecord = (index) => {
      records.value.splice(index, 1)
    }

    // 记得 return
    return {
      records,
      setRecords,
      clearRecords,
      deleteRecord,
    }
  },
  {
    // 网页端配置
    // persist: true,
    // 小程序端配置
    persist: {
      storage: {
        getItem(key) {
          return uni.getStorageSync(key)
        },
        setItem(key, value) {
          return uni.setStorageSync(key, value)
        },
      },
    },
  },
)
